package com.ourcraft.informationcollectionsystem.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.Arrays;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 不拦截请求预检
        if (request.getMethod().equals("OPTIONS")) return true;
        // 从请求头中获取Token
        String token = request.getHeader("Token");
        if (token != null) return true;
        // 获取请求的uri
        String uri = request.getRequestURI();
        System.out.println(uri);
        // 白名单请求不进行拦截
        return uri.equals("/user/testConnection") || uri.equals("/user/login") || uri.equals("/user/info")
                || uri.startsWith("/swagger") || uri.startsWith("/v3");
    }
}
